package com.dabai.uitools.view;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * 可以轻松设置 recyclerView Item的边距
 *
 * recyclerView.addItemDecoration(new ChatDetailItemDecoration(20));
 *
 *
 */
public class ChatDetailItemDecoration extends RecyclerView.ItemDecoration {
    private int space;

    public ChatDetailItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;

        if (parent.getChildPosition(view) == 0) {
            outRect.top = space;
        }
    }
}